# import cv2
#
# img = cv2.imread('rgb.jpg')
# cv2.imshow("img", img)
# while True:
#     if cv2.getWindowProperty('img', 0) == -1 or(cv2.waitKey(1) & 0xFF == 32): #当窗口关闭时为-1，显示时为0
#         break
#     cv2.waitKey(1)
# cv2.destroyWindow('img')

# import termios

# fileName = "./leaf.pcd"
#
# cloud = pcl.load_XYZRGB(fileName)
# visual = pcl.pcl_visualization.CloudViewing()
# i = 0
# visual.ShowColorCloud(cloud)
# while(1):
#     id = input()
#     if(id!=''):
#         not (visual.WasStopped())
#     else:
#         break


# print(tensorflow.__version__)
# f = "jpeg12548fdsfa"
# d = f.replace('jpeg','png')
# print(d)

import cv2
import ctypes
from ctypes import *
import cv2
import numpy as np


import mmap
import os
import cv2
import numpy as np

# -----------------Define info in ShareMemory.h-----------------
IMG_HEAD_OFFSET = 12
# typedef struct {
# 	int width;
# 	int height;
# 	int type;
# }ImgInf;       //图像信息12字节

FRAME_NUMBER = 1
FRAME_W = 1920
FRAME_H = 1080
FRAME_W_H = FRAME_W * FRAME_H
FRAME_SIZE = FRAME_W_H * 3
MEMORY_SIZE = (FRAME_SIZE + IMG_HEAD_OFFSET) * FRAME_NUMBER

sShareMemName = "ShareMedia"

if __name__ == "__main__":
    fpx = mmap.mmap(-1, FRAME_SIZE+IMG_HEAD_OFFSET, sShareMemName)

    # Read img as numpy
    cv2.namedWindow("python_sharedmem_show",0)
    t0 = cv2.getTickCount()
    N = 50
    nFrame = 0
    fps = 0
    while 1:
        nFrame += 1
        img = np.frombuffer(fpx, dtype=np.uint8)
        img = img[IMG_HEAD_OFFSET:FRAME_SIZE+IMG_HEAD_OFFSET]
        img = img.reshape((FRAME_H,FRAME_W,3))

		# Print Average  FPS
        if nFrame % 50 == 0:
            t1 = cv2.getTickCount()
            fps = N*cv2.getTickFrequency() / (t1 - t0)
            t0 = t1
        cv2.putText(img, "Average FPS:" + str(fps) + "fps", (100, 200), cv2.FONT_HERSHEY_COMPLEX, 1, (100, 200, 200), 1)
        cv2.imshow("python_sharedmem_show", img)
        img = None
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cv2.destroyAllWindows()









